package com.example.demo.Test;

import java.sql.*;

public class JBtest {
    //自己数据库的账号和密码，以及自己的端口号（一般端口号都为3306）5.5版本以下的数据库（characterEncoding = utf8&&useSSL=false&serverTimezone=UTC"）不用写
    public static final String URL = "jdbc:mysql://jxsql.shenzhuo.vip:12316/Demo?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
    public static final String USERNAME = "admin";
    public static final String PASSWORD = "jx@123456";

    public static Connection conn;
    public static Connection getConn() {

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try {
                conn=DriverManager.getConnection(URL, USERNAME, PASSWORD);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return conn;
    }

    //关闭数据库连接
    public static void closeConn(Connection conn){
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        System.out.println(getConn());
        closeConn(conn);
    }

}


